package com.jeeplus.test.tools.resp;

import com.jeeplus.test.tools.enums.GlobalResultCode;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("返回代码")
    private String code;
    @ApiModelProperty("返回数据")
    private T data;
    @ApiModelProperty("返回数据提示")
    private String msg;

    public static <T> R<T> suc(T data) {
        return new R(GlobalResultCode.SUC.getCode(), data, GlobalResultCode.SUC.getMsg());
    }

    public static <T> R<T> suc() {
        return (new R()).setCode(GlobalResultCode.SUC.getCode()).setMsg(GlobalResultCode.SUC.getMsg());
    }

    public boolean ifSuc() {
        return "0000".equals(this.code);
    }

    public static <T> R<T> error() {
        return (new R()).setCode(GlobalResultCode.UNKNOW_ERROR.getCode()).setMsg(GlobalResultCode.UNKNOW_ERROR.getMsg());
    }

    public static <T> R<T> error(String code, String msg) {
        return (new R()).setCode(code).setMsg(msg);
    }

    public static <T> R<T> error(GlobalResultCode resultCode) {
        return (new R()).setCode(resultCode.getCode()).setMsg(resultCode.getMsg());
    }

    public String getCode() {
        return this.code;
    }

    public T getData() {
        return this.data;
    }

    public String getMsg() {
        return this.msg;
    }

    public R<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public R<T> setData(T data) {
        this.data = data;
        return this;
    }

    public R<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof R)) {
            return false;
        } else {
            R<?> other = (R)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label47: {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label47;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label47;
                    }

                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof R;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        return result;
    }

    public String toString() {
        String var10000 = this.getCode();
        return "R(code=" + var10000 + ", data=" + this.getData() + ", msg=" + this.getMsg() + ")";
    }

    public R(String code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public R() {
    }
}
